package com.ams.thread.lesson2;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author： 乐哥聊编程(全平台同号)
 */
@Slf4j
public class Example9 {

    public static void main(String[] args) {
        BeautifulStopThread run = new BeautifulStopThread();
        Thread beautifulStopThread = new Thread(run);
        beautifulStopThread.start();
        ThreadUtil.sleep(5000);
//        run.stop();
        beautifulStopThread.interrupt();

    }
    static class BeautifulStopThread implements Runnable {
        private volatile boolean boolStop = false;
        @Override
        public void run() {
            synchronized (Example9.class) {
                while (!boolStop && !Thread.currentThread().isInterrupted()) {
                    log.info("BeautifulStopThread running");
                }
                log.info("BeautifulStopThread stop");
            }
        }
        public void stop() {
            this.boolStop = true;
        }
    }
}
